package com.zhuiyi.yiqingbackend.controller;

import com.zhuiyi.yiqingbackend.common.BaseResponse;
import com.zhuiyi.yiqingbackend.common.ResultUtils;
import com.zhuiyi.yiqingbackend.domain.request.AddTouchRequest;
import com.zhuiyi.yiqingbackend.domain.request.UpdateTouchRequest;
import com.zhuiyi.yiqingbackend.domain.response.TouchResponse;
import com.zhuiyi.yiqingbackend.service.TouchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//@Controller 踩坑了 swagger 返回404  但是没有@Responsebody注解， 由于没有响应模板，Spring并不知道该如何处理，就会出现404错误
@RestController
@RequestMapping("/touch")
@Api(value = "密接者接口", tags = "密接者接口")
@CrossOrigin
public class TouchController {

    @Resource
    private TouchService touchService;


    @PostMapping("/addtouch")
    @ApiOperation(value = "添加密接者", notes = "添加密接者")
    public BaseResponse<Boolean> addTouch(@RequestBody  AddTouchRequest request){
        boolean result = touchService.addTouch(request);
        return ResultUtils.success(result);
    }
    @GetMapping("/getAlltouch")
    @ApiOperation(value = "获取所有密接者", notes = "获取所有密接者")
    public BaseResponse<List<TouchResponse>> getAllTouch(){
        List<TouchResponse> allTouch = touchService.getAllTouch();
        return ResultUtils.success(allTouch);
    }
    @GetMapping("/getTouchById/{id}")
    @ApiOperation(value = "根据ID获取密接者", notes = "根据ID获取密接者")
    public BaseResponse<List<TouchResponse>> getTouchById(@PathVariable int id){
        List<TouchResponse> touch = touchService.getTouchById(id);
        return ResultUtils.success(touch);
    }
    @PostMapping("/update")
    @ApiOperation(value = "更新密接者", notes = "更新密接者")
    public BaseResponse<Boolean> updateTouch(@RequestBody UpdateTouchRequest request){
        boolean result = touchService.updateTouch(request);
        return ResultUtils.success(result);
    }
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "根据ID删除密接者", notes = "根据ID删除密接者")
    public BaseResponse<Boolean> deleteTouchById(@PathVariable int id){
        boolean result = touchService.deleteTouchById(id);
        return ResultUtils.success(result);
    }
}
